import {
  PLATFORMS,
  EXPRESS_COMPANIES,
  PAYMENT_METHODS,
  CUSTOMER_STATUS,
} from "./constants.js";

// 获取平台标签
export const getPlatformLabel = (platform) => {
  return PLATFORMS[platform]?.label || platform;
};

// 获取平台标签类型
export const getPlatformTagType = (platform) => {
  return PLATFORMS[platform]?.type || "";
};

// 获取快递公司标签
export const getExpressLabel = (express) => {
  return EXPRESS_COMPANIES[express] || express;
};

// 获取交易方式标签
export const getPaymentMethodLabel = (method) => {
  return PAYMENT_METHODS[method] || method;
};

// 获取客户状态配置
export const getCustomerStatusConfig = (status) => {
  return CUSTOMER_STATUS[status] || { label: status, type: "" };
};

// 格式化日期
export const formatDate = (dateString) => {
  if (!dateString) return "-";
  return new Date(dateString).toLocaleString("zh-CN");
};

// 获取图片完整URL
export const getImageUrl = (url) => {
  if (!url) return "";
  if (url.startsWith("http")) return url;
  return `${
    import.meta.env.VITE_API_BASE_URL?.replace("/api", "") ||
    "http://localhost:3000"
  }${url}`;
};

// 获取支付状态类型
export const getPaymentStatusType = (record) => {
  const actualAmount = record.actualAmount || 0;
  const totalAmount = record.totalAmount || 0;

  if (actualAmount === 0) return "danger";
  if (actualAmount >= totalAmount) return "success";
  return "warning";
};

// 获取支付状态文本
export const getPaymentStatusText = (record) => {
  const actualAmount = record.actualAmount || 0;
  const totalAmount = record.totalAmount || 0;

  if (actualAmount === 0) return "未付";
  if (actualAmount >= totalAmount) return "已付";
  return `${actualAmount}/${totalAmount}`;
};

// 显示空值
export const displayEmptyValue = (value) => {
  return value || "-";
};

// 计算剩余面单数量
export const calculateRemainingWaybills = (recharged = 0, used = 0) => {
  return Math.max(0, recharged - used);
};
